package com.sam.config;

import android.app.Application;
import android.content.Context;

import com.alibaba.android.arouter.launcher.ARouter;
import com.jess.arms.base.delegate.AppLifecycles;
import com.jess.arms.utils.ArmsUtils;
import com.sam.BuildConfig;
import com.sam.utils.Log;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import butterknife.ButterKnife;
import timber.log.Timber;

public class AppLifecyclesImpl implements AppLifecycles {
    @Override
    public void attachBaseContext(Context base) {

    }

    @Override
    public void onCreate(Application application) {

        if (LeakCanary.isInAnalyzerProcess(application)) {
            return;
        }
        new Log.Builder(application)
                .setBorderSwitch(true)
                .setGlobalTag("SamTag")
                .setLog2FileSwitch(false)
                .setLogSwitch(true)
        ;
        //debug模式下初始化
        if (BuildConfig.LOG_DEBUG) {
            ButterKnife.setDebug(true);
            ARouter.openDebug();
            ARouter.openLog();     // 打印日志
            Timber.plant(new Timber.DebugTree());
        }
        ARouter.init(application);

        ArmsUtils.obtainAppComponentFromContext(application).extras()
                .put(IntelligentCache.getKeyOfKeep(RefWatcher.class.getName())
                        ,
                        BuildConfig.USE_CANARY ?
                                LeakCanary.install(application)
                                : RefWatcher.DISABLED);


    }

    @Override
    public void onTerminate(Application application) {

    }
}
